package Model;

import java.util.ArrayList;
import java.util.Date;

import DAO.XML_DAO;

public class Project implements ISerializable {

    public String projectName;
    public String projectDescription;
    public Date projectStartDate;
    public Date projectFinishDate;
    public ArrayList<Task> projectTaskList = new ArrayList<Task>();

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Project").append("\n");

        sb.append("Name: ").append(projectName).append("\n");
        sb.append("Description: ").append(projectDescription).append("\n");
        sb.append("StartDate: ").append(XML_DAO.fromDateToString(projectStartDate)).append("\n");
        sb.append("FinishDate: ").append(XML_DAO.fromDateToString(projectFinishDate)).append("\n");

        sb.append("TASK").append("\n");

        for (Task t : projectTaskList) {
            t.print("   ", sb);
        }

        return sb.toString();
    }

    public String toText(){
        StringBuilder sb = new StringBuilder();
        long daysCount = this.projectFinishDate.getTime() / this.projectStartDate.getTime();
        daysCount = daysCount / (1000 * 60 * 60 * 24);
        
        sb.append(this.projectName).append("||");
        sb.append(this.projectDescription).append("||");
        sb.append(XML_DAO.fromDateToString(projectStartDate)).append("||");
        sb.append(XML_DAO.fromDateToString(projectFinishDate)).append("||");
        sb.append(daysCount).append("||");
        
        for(Task t : this.projectTaskList){
            sb.append(t.toText(this.projectStartDate));
        }
        
        return sb.toString();
    }
    
    public static Project TestProject(String name) {
        Project p = new Project();

        Date d1 = XML_DAO.fromStringToDate("31/10/2013");
        Date d2 = XML_DAO.fromStringToDate("30/11/2013");

        p.projectName = name;
        p.projectDescription = "Esto es un proyecto de prueba";
        p.projectStartDate = d1;
        p.projectFinishDate = d2;
        p.projectTaskList.add(new Task("Requerimientos", "description", d1, XML_DAO.fromStringToDate("10/11/2013"), 10));
        p.projectTaskList.add(new Task("Elicitación", "description2", d1, XML_DAO.fromStringToDate("5/11/2013"), 10));
        p.projectTaskList.add(new Task("Casos de uso", "description2", XML_DAO.fromStringToDate("5/11/2013"), XML_DAO.fromStringToDate("10/11/2013"), 10));
        p.projectTaskList.add(new Task("Tarea 4", "description2", XML_DAO.fromStringToDate("12/11/2013"), XML_DAO.fromStringToDate("20/11/2013"), 10));
        p.projectTaskList.add(new Task("Tarea 5", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 10));
        p.projectTaskList.add(new Task("Tarea 5", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 10));
        
        p.projectTaskList.add(new Task("Tarea 6", "description", d1, XML_DAO.fromStringToDate("10/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 7", "description2", d1, XML_DAO.fromStringToDate("5/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 8", "description2", XML_DAO.fromStringToDate("5/11/2013"), XML_DAO.fromStringToDate("10/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 9", "description2", XML_DAO.fromStringToDate("12/11/2013"), XML_DAO.fromStringToDate("20/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 10", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 11", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 15));
        
        p.projectTaskList.add(new Task("Tarea 12", "description", d1, XML_DAO.fromStringToDate("10/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 13", "description2", XML_DAO.fromStringToDate("5/11/2013"), XML_DAO.fromStringToDate("10/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 14", "description2", XML_DAO.fromStringToDate("12/11/2013"), XML_DAO.fromStringToDate("20/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 15", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 15));
        p.projectTaskList.add(new Task("Tarea 16", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 15));
        
        p.projectTaskList.add(new Task("Tarea 17", "description", d1, XML_DAO.fromStringToDate("10/11/2013"), 20));
        p.projectTaskList.add(new Task("Tarea 18", "description2", d1, XML_DAO.fromStringToDate("5/11/2013"), 20));
        p.projectTaskList.add(new Task("Tarea 19", "description2", XML_DAO.fromStringToDate("5/11/2013"), XML_DAO.fromStringToDate("10/11/2013"), 20));
        p.projectTaskList.add(new Task("Tarea 20", "description2", XML_DAO.fromStringToDate("12/11/2013"), XML_DAO.fromStringToDate("20/11/2013"), 20));
        p.projectTaskList.add(new Task("Tarea 21", "description3", XML_DAO.fromStringToDate("18/11/2013"), XML_DAO.fromStringToDate("31/11/2013"), 20));
        
        return p;
    }
}
